export default function (map, radius, blur, display, n) {
  // 事故多发地,热力图
  var vector = null

  const changeRadius = (n) => {
    vector.setRadius(parseInt(n, 10))
  }
  const changeBlur = (n) => {
    vector.setBlur(parseInt(n, 10))
  }

  const showHotMap = (map, radius, blur, display) => {
    display.value = true
    //创建一个Heatmap图层
    vector = new ol.layer.Heatmap({
      //矢量数据源（读取本地的KML数据）
      source: new ol.source.Vector({
        url: '@/../event.kml',
        format: new ol.format.KML({
          extractStyles: false,
        }),
      }),
      //热点半径
      radius: parseInt(radius.value, 10),
      //模糊尺寸
      blur: parseInt(blur.value, 10),
    })

    //为矢量数据源添加addfeature事件监听
    vector.getSource().on('addfeature', function (event) {
      //要素的名称属性
      var name = event.feature.get('name')
      //得到要素的地震震级属性（magnitude）
      var magnitude = parseFloat(name.substr(2))
      //设置要素的weight属性
      event.feature.set('weight', magnitude - 5)
    })
    map.value.addLayer(vector)
  }

  const closeHotMap = (map, display) => {
    display.value = false
    map.value.getLayers().array_.splice(5, 1)
    map.value.render()
  }
  return { changeRadius, changeBlur, showHotMap, closeHotMap }
}
